package com.feng.controller.front;

import com.feng.dto.NewsDto;
import com.feng.service.NewsService;
import com.feng.vo.FrontPageVo;
import com.feng.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: 丰
 * @date: 2023/1/1 17:01
 */
@RestController
@RequestMapping("/front/news")
@Api(tags = "前台新闻接口")
public class FrontNewsController {

    @Autowired
    private NewsService newsService;

    @ApiOperation("通过id查询")
    @GetMapping("/findById/{id}")
    public ResultVo<List<NewsDto>> findById(@PathVariable("id") Integer id){
        return newsService.findByIdFront(id);
    }

    @ApiOperation("查询第几页的推荐新闻")
    @GetMapping("/recommend/{page}")
    public Object recommend(@PathVariable("page") Integer page){
        return newsService.recommend(page);
    }

    @ApiOperation("查询推荐新闻的总条数")
    @GetMapping("/countRecommend")
    public ResultVo<Integer> countRecommend(){
        return newsService.countRecommend();
    }

    @ApiOperation("查询指定分类下的新闻")
    @GetMapping("/getAll")
    public ResultVo<List<NewsDto>> getAll(FrontPageVo pageVo){
        return newsService.getAll(pageVo);
    }

}
